home *** CD-ROM | disk | FTP | other *** search
- /* Fade In Vol */
- /* v 1.0 */
- /* 1995 by ANR */
-
- // Usage:
- // A small example of to use Digital Editor Plugs with a MODAL DIALOG
-
- #include "MAD.h"
- #include "PPPlug.h"
-
- #if defined(powerc) || defined(__powerc)
- enum {
- PlayerPROPlug = kCStackBased
- | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Pcmd*)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( PPInfoPlug*)))
- };
-
- ProcInfoType __procinfo = PlayerPROPlug;
- #else
- #include <A4Stuff.h>
- #endif
-
- void GetDText (DialogPtr dlog, short item, StringPtr str)
- {
- Handle itemHandle;
- short itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- GetIText (itemHandle, str);
- }
-
- void SetDText (DialogPtr dlog, short item, Str255 str)
- {
- Handle itemHandle;
- short itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- SetIText (itemHandle, str);
- }
-
- GDHandle TheGDevice:0xCC8;
-
- void AutoPosition( DialogPtr aDia)
- {
- Point Position, mouse;
- Rect ViewRect;
- short XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
-
- GetMouse( &mouse);
- LocalToGlobal( &mouse);
-
- SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
- (*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
-
- Position.h = mouse.h - XSize/2;
- if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
- else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
-
- Position.v = mouse.v - YSize/2;
- if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
- else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
-
- MoveWindow( aDia, Position.h, Position.v, false);
-
- ShowWindow( aDia);
- }
-
- Cmd* GetCmd( short row, short track, Pcmd* myPcmd)
- {
- if( row < 0) row = 0;
- else if( row >= myPcmd->length) row = myPcmd->length -1;
-
- if( track < 0) track = 0;
- else if( track >= myPcmd->tracks) track = myPcmd->tracks -1;
-
- return( &(myPcmd->myCmd[ (myPcmd->length * track) + row]));
- }
-
- void pStrcpy(register unsigned char *s1, register unsigned char *s2)
- {
- register short len, i;
-
- len = *s2;
- for ( i = 0; i <= len; i++) s1[ i] = s2[ i];
- }
-
- void OctavesName(short id, Str255 String)
- {
- short NNames[ 12] = {'C ','C#','D ','D#','E ','F ','F#','G ','G#','A ','A#','B '};
- Str255 WorkStr;
-
- if( id == 0xFF)
- {
- pStrcpy( String, "\p---");
- return;
- }
-
- NumToString( (id / 12), WorkStr);
- String[ 0] = 3;
- String[ 1] = NNames[ (id) % 12]>>8;
- String[ 2] = NNames[ (id) % 12];
- String[ 3] = WorkStr[ 1];
- }
-
- MenuHandle CreateMenu()
- {
- MenuHandle returnMenu;
- short i;
- Str255 aStr;
-
- returnMenu = GetMenu( 141);
-
- OctavesName( 1, aStr); SetItem( returnMenu, 1, aStr);
- for( i = 1; i < 96; i++)
- {
- OctavesName( i, aStr);
- AppendMenu( returnMenu, aStr);
- }
-
- return returnMenu;
- }
-
- short Text2Note( Str255 myTT)
- {
- short Oct;
-
- Oct = myTT[ 3] - 48;
- Oct *= 12;
-
- // 0 1 2 3 4 5 6 7 8 9 10 11
- // C- C# D- D# E- F- F# G- G# A- A# B-
- switch( myTT[1])
- {
- case 'C': case'c': Oct += 0; break;
- case 'D': case'd': Oct += 2; break;
- case 'E': case'e': Oct += 4; break;
- case 'F': case'f': Oct += 5; break;
- case 'G': case'g': Oct += 7; break;
- case 'A': case'a': Oct += 9; break;
- case 'B': case'b': Oct += 11; break;
-
- default: Oct = 0xFF; break;
- }
-
- if( Oct != 0xFF)
- {
- if( myTT[ 2] == '#') Oct++;
- if( Oct >= 96) Oct = 0xFF;
- if( Oct < 0) Oct = 0xFF;
- }
-
- return( Oct);
- }
-
- OSErr main( Pcmd *myPcmd,
- PPInfoPlug *thePPInfoPlug)
- {
- DialogPtr myDia;
- short itemHit, itemType;
- Rect itemRect;
- Handle itemHandle;
- Str255 aStr;
- MenuHandle noteMenu;
- Point myPt;
- long Result;
-
- #ifndef powerc
- long oldA4 = SetCurrentA4(); //this call is necessary for strings in 68k code resources
- #endif
-
- myDia = GetNewDialog( 128, 0L, (WindowPtr) -1L);
- SetPort( myDia);
- AutoPosition( myDia);
-
- SetDText( myDia, 3, "\pC 3");
- SetDText( myDia, 4, "\pC 7");
- SelIText( myDia, 3, 0, 200);
-
- noteMenu = CreateMenu();
-
- do
- {
- RESTART:
-
- #if defined(powerc) || defined(__powerc)
- ModalDialog( thePPInfoPlug->MyDlgFilterUPP, &itemHit);
- #else
- ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
- #endif
-
- switch( itemHit)
- {
- case 7:
- case 8:
- InsertMenu( noteMenu, hierMenu);
-
- GetDItem( myDia, itemHit, &itemType, &itemHandle, &itemRect);
- myPt.v = itemRect.top; myPt.h = itemRect.left;
- LocalToGlobal( &myPt);
-
- GetDText( myDia, itemHit-4, aStr);
- SetItemMark( noteMenu, Text2Note( aStr) + 1, 0xa5);
-
- Result = PopUpMenuSelect( noteMenu,
- myPt.v,
- myPt.h,
- Text2Note( aStr) + 1);
-
- SetItemMark( noteMenu, Text2Note( aStr) + 1, 0);
-
- if ( HiWord( Result ) != 0 )
- {
- OSErr iErr;
-
- OctavesName( LoWord( Result)-1, aStr);
- SetDText( myDia, itemHit-4, aStr);
- SelIText( myDia, 3, 0, 200);
- }
-
- DeleteMenu( (*noteMenu)->menuID);
- break;
- }
- }while( itemHit != 1 && itemHit != 2);
-
- if( itemHit == 1)
- {
- short track, row;
- long from, to;
- Cmd *myCmd;
-
- GetDText( myDia, 3, aStr); from = Text2Note( aStr);
- GetDText( myDia, 4, aStr); to = Text2Note( aStr);
-
- // Check values
-
- if( from < 0 || from >= 96)
- {
- SelIText( myDia, 3, 0, 200);
- SysBeep( 1);
- goto RESTART;
- }
-
- if( to < 0 || to >= 96)
- {
- SelIText( myDia, 4, 0, 200);
- SysBeep( 1);
- goto RESTART;
- }
-
- for( track = 0; track < myPcmd->tracks; track++)
- {
- for( row = 0; row < myPcmd->length; row++)
- {
- myCmd = GetCmd( row, track, myPcmd);
-
- if( myPcmd->length > 1) // no zero div !!
- myCmd->note = from + ((to-from) * row) / (myPcmd->length-1);
-
- // my fade command : 0x10 min vol, 0x50 : max vol
- // Refer to MAD description for more informations
- }
- }
- }
-
- DisposDialog( myDia);
-
- #ifndef powerc
- SetA4( oldA4);
- #endif
-
- ReleaseResource( (Handle) noteMenu);
-
- return noErr;
- }